package com.ptmall.app.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.bean.ProductBean;
import com.ptmall.app.ui.activity.GoodDetilActivity;
import com.ptmall.app.utils.GlideUtil;

import java.util.List;


/**
 * Created by Administrator on 2018/1/12.
 */

public class GoodListAdapter2 extends BaseAdapter {

    private Context mContext;
    private List<ProductBean> mDataList;
    private LayoutInflater mLayoutInflater;

    public void setClickInterface(ClickInterface clickInterface){
        this.clickInterface = clickInterface;
    }

    public ClickInterface clickInterface;

    public GoodListAdapter2(Context context, List<ProductBean> list) {
        this.mContext = context;
        this.mDataList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void pushData(List<ProductBean> list){
        this.mDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if(mDataList == null){
            return 0;
        }
        return mDataList.size();
    }


    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = mLayoutInflater.inflate(R.layout.item_gridgood22, parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        ProductBean bean = mDataList.get(position);

//        viewHolder.goodname.setText(bean.product_name);
//        viewHolder.sellprice.setText("￥"+bean.sell_price);
//        if(bean.is_tejia == null||bean.is_tejia.equals("1")){
//            viewHolder.activi_rel.setVisibility(View.GONE);
//        }else {
//            viewHolder.activi_rel.setVisibility(View.VISIBLE);
//
//        }
//
//
//        if (!TextUtils.isEmpty(bean.manjian)) {
//            viewHolder.activi_rel.setVisibility(View.VISIBLE);
//            viewHolder.activi_text.setText(bean.manjian);
//        }
//        GlideUtil.showImg(mContext,bean.list_img,viewHolder.img);
//
//        viewHolder.addcar.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                clickInterface.shopcaradd(viewHolder.img,bean.productId,position);
//            }
//        });
//        viewHolder.img.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(mContext, GoodDetilActivity.class);
//                intent.putExtra("id",bean.productId);
//                mContext.startActivity(intent);
//            }
//        });
//        viewHolder.specname.setText(bean.specs_name);

        return convertView;
    }

    class ViewHolder {

        TextView activi_text,goodname,sellprice,specname;
        ImageView img,addcar;
        RelativeLayout activi_rel;

        ViewHolder(View view) {
            img = (ImageView) view.findViewById(R.id.img);
            addcar = (ImageView) view.findViewById(R.id.addcar);
            activi_rel = (RelativeLayout) view.findViewById(R.id.activi_rel);
            activi_text = (TextView) view.findViewById(R.id.activi_text);
            goodname = (TextView) view.findViewById(R.id.goodname);
            sellprice = (TextView) view.findViewById(R.id.sellprice);
            specname = (TextView) view.findViewById(R.id.specname);
        }
    }


    public interface ClickInterface{
        void shopcaradd(ImageView iv, String id, int position);
    }


}
